/**
 *
 */
package com.yunshipei.utils;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.hardware.Camera;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import com.yunshipei.EnterApplication;
import com.yunshipei.common.manager.EnterConfig;
import com.yunshipei.enterplorer.R;

import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EncodingUtils;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import okhttp3.HttpUrl;

/**
 * @author cWX223941
 */
public class BaseUtil {

    /**
     * if params is not null,then add the params into url for get request
     *
     * @param params
     * @param urlStr
     */
    public static URL getUrl(List<BasicNameValuePair> params, String urlStr)
            throws Exception {
        URL url = null;
        if (params != null) {
            String urlInfo = StringUtil.getGetUrl(params, urlStr);
            url = new URL(urlInfo);
        } else {
            url = new URL(urlStr);
        }
        return url;
    }

    public static void hideKeyBoard(Context context) {
        Activity activity = (Activity) context;
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive() && activity.getCurrentFocus() != null) {
            if (activity.getCurrentFocus().getWindowToken() != null) {
                imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    }

    public static String getString(InputStream inputStream) {
        InputStreamReader inputStreamReader = null;
        try {
            inputStreamReader = new InputStreamReader(inputStream, "utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        BufferedReader reader = new BufferedReader(inputStreamReader);
        StringBuffer sb = new StringBuffer("");
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line);
                sb.append("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

    private final static byte[] hex = "0123456789ABCDEF".getBytes();

    public static String Bytes2HexString(byte[] b) {
        byte[] buff = new byte[2 * b.length];
        for (int i = 0; i < b.length; i++) {
            buff[2 * i] = hex[(b[i] >> 4) & 0x0f];
            buff[2 * i + 1] = hex[b[i] & 0x0f];
        }
        return new String(buff);
    }

    public static DisplayMetrics getDisplayMetrics(Context context) {
        DisplayMetrics displaymetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService(
                Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(
                displaymetrics);
        return displaymetrics;
    }

    public static float getScreenWidth(Context context) {
        return getDisplayMetrics(context).widthPixels;
    }

    public static float getScreenHeight(Context context) {
        return getDisplayMetrics(context).heightPixels;
    }

    public static float getStandSize(Context context) {
        float width = getScreenWidth(context);
        float height = getScreenHeight(context);
        if (width > height) {
            return height;
        } else {
            return width;
        }
    }

    public static int[] getRealScreenSize(Activity activity) {
        int[] size = new int[2];
        int screenWidth = 0, screenHeight = 0;
        WindowManager w = activity.getWindowManager();
        Display d = w.getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        d.getMetrics(metrics);
        // since SDK_INT = 1;
        screenWidth = metrics.widthPixels;
        screenHeight = metrics.heightPixels;
        // includes window decorations (statusbar bar/menu bar)
        if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
            try {
                screenWidth = (Integer) Display.class.getMethod("getRawWidth")
                        .invoke(d);
                screenHeight = (Integer) Display.class
                        .getMethod("getRawHeight").invoke(d);
            } catch (Exception ignored) {
            }
        // includes window decorations (statusbar bar/menu bar)
        if (Build.VERSION.SDK_INT >= 17)
            try {
                Point realSize = new Point();
                Display.class.getMethod("getRealSize", Point.class).invoke(d,
                        realSize);
                screenWidth = realSize.x;
                screenHeight = realSize.y;
            } catch (Exception ignored) {
            }
        size[0] = screenWidth;
        size[1] = screenHeight;
        return size;
    }

    private static Boolean isTablet = null;

    public static boolean isTablet() {
        if (isTablet == null) {
            boolean flag;
            if ((0xf & EnterApplication.getApp().getResources().getConfiguration().screenLayout) >= 3)
                flag = true;
            else
                flag = false;
            isTablet = Boolean.valueOf(flag);
        }
        return isTablet.booleanValue();
    }

    public static int getVersionCode() {
        int versionCode = 0;
        try {
            versionCode = EnterApplication.getApp().getPackageManager()
                    .getPackageInfo(EnterApplication.getApp().getPackageName(),
                            0).versionCode;
        } catch (PackageManager.NameNotFoundException ex) {
            versionCode = 0;
        }
        return versionCode;
    }

    public static String getVersionName() {
        String versionName = "";
        try {
            versionName = EnterApplication.getApp().getPackageManager()
                    .getPackageInfo(EnterApplication.getApp().getPackageName(),
                            0).versionName;
        } catch (PackageManager.NameNotFoundException ex) {
            ex.printStackTrace();
        }
        return versionName;
    }

    public static String readAssertResource(Context context, String strAssertFileName) {
        AssetManager assetManager = context.getAssets();
        String strResponse = "";
        try {
            InputStream ims = assetManager.open(strAssertFileName);
            strResponse = getStringFromInputStream(ims);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return strResponse;
    }

    private static String getStringFromInputStream(InputStream a_is) {
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();
        String line;
        try {
            br = new BufferedReader(new InputStreamReader(a_is));
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }
        }
        return sb.toString();
    }

    public static void installAPK(Context context, File file) {
        if (file == null || !file.exists())
            return;
        Intent intent = new Intent();
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file),
                "application/vnd.android.package-archive");
        context.startActivity(intent);
    }

    public static long getFileSize(File file) throws Exception {
        long size = 0;
        if (file.exists()) {
            FileInputStream fis = null;
            fis = new FileInputStream(file);
            size = fis.available();
            fis.close();
            return size;
        } else {
            return 0;
        }
    }

    public static boolean isMatchedAddress(String address) {
        String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(address);
        return matcher.matches();
    }

    public static String getDeviceInfo(Context context) {
        try {
            org.json.JSONObject json = new org.json.JSONObject();
            android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);

            String device_id = tm.getDeviceId();

            android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context.getSystemService(Context.WIFI_SERVICE);

            String mac = wifi.getConnectionInfo().getMacAddress();
            json.put("mac", mac);

            if (TextUtils.isEmpty(device_id)) {
                device_id = mac;
            }

            if (TextUtils.isEmpty(device_id)) {
                device_id = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
            }

            json.put("device_id", device_id);

            return json.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void deletePathReal(String path) {
        File file = new File(path);
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] files = file.listFiles();
                if (files != null && files.length > 0) {
                    for (File temp : files) {
                        deletePathReal(temp.getPath());
                    }
                }
                file.delete();
            } else {
                file.delete();
            }
        }
    }

    public static void deletePathReal(String path, String retainPath) {
        if (path.equals(retainPath))
            return;
        File file = new File(path);
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] files = file.listFiles();
                if (files != null && files.length > 0) {
                    for (File temp : files) {
                        if (!TextUtils.isEmpty(temp.getPath()) && !temp.getPath().equals(retainPath))
                            deletePathReal(temp.getPath());
                    }
                }
                file.delete();
            } else {
                file.delete();
            }
        }
    }

    public static void deleteFile(String filePath) {
        deleteFile(filePath, null);
    }

    /**
     * delete files
     *
     * @param filePath   要删除的文件目录
     * @param retainPath 要删除文件目录中保留下来的文件 or 目录
     */
    public static void deleteFile(String filePath, String retainPath) {
        File file = new File(filePath);
        if (file.exists()) {
            if (!file.isDirectory()) {
                file.delete();
            } else {
                deletePathReal(file.getAbsolutePath(), retainPath);
            }
        }
    }

    public static void deleteFile(File file) {
        if (file.exists()) {
            if (!file.isDirectory()) {
                file.delete();
            } else {
                deletePathReal(file.getAbsolutePath());
            }
        }
    }

    public static void deleteFileHoldPath(String path) {
        File[] files = new File(path).listFiles();
        if (files != null && files.length > 0) {
            for (File file : files) {
                if (file.exists()) {
                    if (!file.isDirectory()) {
                        file.delete();
                    } else {
                        deletePathReal(file.getAbsolutePath());
                    }
                }
            }
        }
    }

    public static int dip2px(Context context, int dipValue) {
        float scale = getDisplayMetrics(context).density;
        return (int) (dipValue * scale + 0.5f);
    }

    public static String getCurProcessName(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
            if (appProcess.pid == pid) {
                return appProcess.processName;
            }
        }
        return null;
    }

    public static Process clearAppUserData(String packageName) {
        Process p = execRuntimeProcess("pm clear " + packageName);
        if (p == null) {
            System.out.println("Clear app data packageName:" + packageName
                    + ", FAILED !");
        } else {
            System.out.println("Clear app data packageName:" + packageName
                    + ", SUCCESS !");
        }
        return p;
    }

    public static Process execRuntimeProcess(String commond) {
        Process p = null;
        try {
            p = Runtime.getRuntime().exec(commond);
        } catch (IOException e) {
            System.out.println("exec Runtime commond:" + commond + ", IOException" + e);
            e.printStackTrace();
        }
        System.out.println("exec Runtime commond:" + commond + ", Process:" + p);
        return p;
    }

    public static boolean unZip(File zipFile, String path) {
        File targetDirectory = new File(path);
        if (!targetDirectory.exists()) {
            targetDirectory.mkdirs();
        }

        ZipInputStream zis = null;
        try {
            zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
            ZipEntry ze;
            int count;
            byte[] buffer = new byte[8192];
            while ((ze = zis.getNextEntry()) != null) {
                File file = new File(targetDirectory, ze.getName());
                File dir = ze.isDirectory() ? file : file.getParentFile();
                if (!dir.isDirectory() && !dir.mkdirs())
                    throw new FileNotFoundException("Failed to ensure directory: " + dir.getAbsolutePath());
                if (ze.isDirectory())
                    continue;
                FileOutputStream fout = new FileOutputStream(file);
                try {
                    while ((count = zis.read(buffer)) != -1)
                        fout.write(buffer, 0, count);
                } finally {
                    fout.close();
                }
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                if (zis != null) {
                    zis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static String readFileSdcard(String fileName) {
        String res = "";
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(fileName);
            int length = fis.available();
            byte[] buffer = new byte[length];
            fis.read(buffer);
            res = EncodingUtils.getString(buffer, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return res;
    }

    public static int getNavigationBarHeight(Context context) {
        final boolean isMeiZu = Build.MANUFACTURER.equalsIgnoreCase("meizu");

        final boolean autoHideSmartBar = Settings.System.getInt(context.getContentResolver(),
                "mz_smartbar_auto_hide", 0) == 1;

        if (isMeiZu) {
            if (autoHideSmartBar) {
                return 0;
            } else {
                try {
                    Class c = Class.forName("com.android.internal.R$dimen");
                    Object obj = c.newInstance();
                    Field field = c.getField("mz_action_button_min_height");
                    int height = Integer.parseInt(field.get(obj).toString());
                    return context.getResources().getDimensionPixelSize(height);
                } catch (Throwable e) { // 不自动隐藏smartbar同时又没有smartbar高度字段供访问，取系统navigationbar的高度
                    return getNormalNavigationBarHeight(context);
                }
            }
        } else {
            return getNormalNavigationBarHeight(context);
        }
    }

    protected static int getNormalNavigationBarHeight(final Context ctx) {
        try {
            final Resources res = ctx.getResources();
            int rid = res.getIdentifier("config_showNavigationBar", "bool", "android");
            if (rid > 0) {
                boolean flag = res.getBoolean(rid);
                if (flag) {
                    int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
                    if (resourceId > 0) {
                        return res.getDimensionPixelSize(resourceId);
                    }
                }
            }
        } catch (Throwable ignored) {
        }
        return 0;
    }

    private static long lastClickTime;

    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (0 < timeD && timeD < 400) {
            return true;
        }
        lastClickTime = time;
        return false;
    }

    public static String inputStream2String(InputStream in) throws Exception {

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] data = new byte[4096];
        int count = -1;
        while ((count = in.read(data, 0, 4096)) != -1)
            outStream.write(data, 0, count);

        data = null;
        return new String(outStream.toByteArray(), "UTF-8");
    }

    //获取当前wifi SSID  如果是wifi并且可用就返回ssid
    public static String getWifiSSID(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI && activeNetInfo.isConnected() && activeNetInfo.isAvailable()) {
            WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
                WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
                String ssId = wifiInfo.getSSID();
                return ssId.substring(1, ssId.length() - 1);
            }
        }
        return "";
    }

    public static byte[] toByteArray(String filePath) throws IOException {
        byte[] buffer = null;
        try {
            File file = new File(filePath);
            FileInputStream fis = new FileInputStream(file);
            ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
            byte[] b = new byte[1000];
            int n;
            while ((n = fis.read(b)) != -1) {
                bos.write(b, 0, n);
            }
            fis.close();
            bos.close();
            buffer = bos.toByteArray();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer;
    }

    //异或解密运行时
    public static byte[] getEnc(String path, String key) throws IOException {
        byte[] chars = key.getBytes();
        int keyLen = key.length();
        try {
            byte[] data = toByteArray(path);
            int dataLen = data.length;

            byte[] result = new byte[dataLen];
            for (int i = 0; i < dataLen; i++) {
                result[i] = (byte) (data[i] ^ chars[i % keyLen]);
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    //获取当前程序主题
    public static int getCurrentTheme() {
        switch (EnterConfig.getInstance().getThemeCode()) {
            case "1":
                return R.style.redAppTheme;
            case "2":
                return R.style.blueAppTheme;
            case "3":
                return R.style.purpleAppTheme;
            case "4":
                return R.style.greenAppTheme;
            case "5":
                return R.style.orangeAppTheme;
            case "6":
                return R.style.blackAppTheme;
            default:
                return R.style.redAppTheme;
        }
    }

    public static ColorStateList getCurrentSwitchButtonColor(Context context) {
        switch (EnterConfig.getInstance().getThemeCode()) {
            case "1":
                return context.getResources().getColorStateList(R.color.switch_button_red_selector);
            case "2":
                return context.getResources().getColorStateList(R.color.switch_button_blue_selector);
            case "3":
                return context.getResources().getColorStateList(R.color.switch_button_purple_selector);
            case "4":
                return context.getResources().getColorStateList(R.color.switch_button_green_selector);
            case "5":
                return context.getResources().getColorStateList(R.color.switch_button_orange_selector);
            case "6":
                return context.getResources().getColorStateList(R.color.switch_button_black_selector);
            default:
                return context.getResources().getColorStateList(R.color.switch_button_red_selector);
        }
    }

    public static String getHost(String url) {
        if (TextUtils.isEmpty(url)) return "";
        Uri uri = Uri.parse(url);
        if (uri != null) {
            return uri.getHost();
        }
        return "";
    }

    public static String replaceBlank(String str) {
        String dest = "";
        if (str != null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }

    public static boolean isURLAvailable(String url) {
        if (TextUtils.isEmpty(url)) {
            return false;
        } else {
            try {
                URL pattern = new URL(url);
                String protocol = pattern.getProtocol();
                if (!protocol.equals("http") && !protocol.equals("https")) {
                    return false;
                }
                int port = pattern.getPort();
                if (port != -1 && port < 0 || port > 65535) {
                    return false;
                }
                if (port == -1 && !url.endsWith(pattern.getHost())) {
                    return false;
                }
                if (HttpUrl.parse(url) == null) {
                    return false;
                }
            } catch (MalformedURLException e) {
                return false;
            }
            return true;
        }
    }

    public static void modifyStatusBarColor(Activity activity, int color) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.getWindow().setStatusBarColor(color);
        }
    }

    public static int parseTextZoomSize(int position) {
        int size = 100;
        switch (position) {
            case 0:
                size = 75;
                break;
            case 1:
                size = 100;
                break;
            case 2:
                size = 110;
                break;
            case 3:
                size = 125;
                break;
            case 4:
                size = 145;
                break;
        }
        return size;
    }

    public static int getStatusBarHeight(Context context) {
        int result = dip2px(context, 25);
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    public static String makeAuthString(String str) {
        StringBuilder indexBuffer = new StringBuilder();
        String sliceStr = encodeMd5(str).substring(0, 4);
        String[] array = getCharArray();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < array.length; j++) {
                if (String.valueOf(sliceStr.charAt(i)).equals(array[j])) {
                    indexBuffer.append(j % 10);
                }
            }
        }
        return indexBuffer.toString();
    }

    private static String[] getCharArray() {
        String array[] = new String[36];
        for (int i = 0; i < 10; i++) {
            array[i] = String.valueOf(i);
        }
        int k = 10;
        for (int j = 97; j < 123; j++) {
            array[k] = String.valueOf((char) j);
            k++;
        }
        return array;
    }

    public static String encodeMd5(String s) {
        char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            byte[] btInput = s.getBytes("UTF-8");
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            mdInst.update(btInput);
            byte[] md = mdInst.digest();
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static boolean isCameraAvailable() {
        boolean canUse = true;
        Camera mCamera = null;
        try {
            mCamera = Camera.open();
            if (mCamera != null) {
                Camera.Parameters mParameters = mCamera.getParameters();
                mCamera.setParameters(mParameters);
            }
        } catch (Exception e) {
            canUse = false;
        }
        if (mCamera != null) {
            mCamera.release();
        }
        return canUse;
    }

    public static void modifyIndexBtnCircleBg(View view, float cTopLeft, float cTopRight, float cBottomLeft, float cBottomRight) {

        int[] mNormalState = new int[]{};
        int[] mPressState = new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled};
        int[] mDisableState = new int[]{-android.R.attr.state_enabled};
        int[] mSelectedState = new int[]{android.R.attr.state_selected, android.R.attr.state_enabled};
        //
        float outRectr[] = new float[]{cTopLeft, cTopLeft, cTopRight, cTopRight, cBottomRight, cBottomRight, cBottomLeft, cBottomLeft};
        // 创建状态管理器 ，根据控件的状态，改变控件显示
        //创建drawable
        StateListDrawable drawable = new StateListDrawable();
        //设置圆角
        RoundRectShape rectShape = new RoundRectShape(outRectr, null, null);
        // 创建按钮按下的状态 并设置圆角
        ShapeDrawable pressedDrawable = new ShapeDrawable(rectShape);
        //创建按钮正常状态 并设置圆角
        ShapeDrawable normalDrawable = new ShapeDrawable(rectShape);
        // 设置我们按钮背景的颜色
        normalDrawable.getPaint().setColor(EnterConfig.getInstance().getGlobalColor());
        pressedDrawable.getPaint().setColor(EnterConfig.getInstance().getStatusBarGlobalColor());
        // 添加点击是按下的状态
        drawable.addState(mPressState, pressedDrawable);
        // 添加正常的状态
        drawable.addState(mNormalState, normalDrawable);
        view.setBackgroundDrawable(drawable);
    }
}
